#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<set>
#include<vector>
using namespace std;
class Solution {
public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
        set<int>set1(nums1.begin(), nums1.end());
        set<int>set2(nums2.begin(), nums2.end());
        vector<int>ret;
        auto it1 = set1.begin();
        auto it2 = set2.begin();
        while (it1 != set1.end() && it2 != set2.end())
        {
            if (*it1 > *it2)
            {
                *it2++;
            }
            else if (*it1 < *it2)
            {
                *it1++;
            }
            else
            {
                ret.push_back(*it1);
                *it2++;
                *it1++;
            }
        }
        return ret;
    }
};

